package experimentForth;

import lombok.Data;

@Data
class File {
    private String filename;
    private String protectionCode;
    private StringBuilder content;
    private int pointer;

    public File(String filename, String protectionCode) {
        this.filename = filename;
        this.protectionCode = protectionCode;
        this.content = new StringBuilder();
        this.pointer = 0;
    }

    // 读取操作
    public String read() {
        if (pointer < content.length()) {
            return String.valueOf(content.charAt(pointer++));
        } else {
            System.out.println("End of file.");
            return null;
        }
    }

    // 写入操作
    public void write(String newContent) {
        content.append(newContent);
    }

    // 设置读写指针
    public void setPointer(int newPointer) {
        if (newPointer >= 0 && newPointer <= content.length()) {
            pointer = newPointer;
        } else {
            System.out.println("Invalid pointer position.");
        }
    }

    // 获取内容（用于debug或展示）
    public String getContent() {
        return content.toString();
    }
}